package com.wjm.demo.test1.net_test.tcp_socket_test.ie_server;

import java.io.InputStream;
import java.io.PrintWriter;
import java.net.Socket;

public class MyBrowser {
    public static void main(String[] args) throws Exception {
//        Socket s=new Socket("192.168.0.101",8080);
        Socket s = new Socket("www.baidu.com", 80);
        PrintWriter pw = new PrintWriter(s.getOutputStream(), true);
//        pw.println("GET /myweb/1.html HTTP/1.1");
//        pw.println("Accept:*/*");
//        pw.println("Host:192.168.0.101:8080");

//        pw.println("GET /myweb/1.html HTTP/1.1");
//        pw.println("HTTP/1.1");
//        pw.println("Accept:*/*");
//        pw.println("Host:www.hao123.com");
//        //https://www.hao123.com/
//        pw.println("Connection:close");

        //访问baidu
        pw.println("GET /500.html HTTP/1.1");
        pw.println("Accept: */*");
        pw.println("Host: www.baidu.com");
        pw.println("Connection: close");

        pw.println();
        pw.println();
        InputStream is = s.getInputStream();
        byte[] buf = new byte[1024];
        int len = is.read(buf);
        String text = new String(buf, 0, len);
        System.out.println(text);
        s.close();

    }
}
